﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 状态者模式
{
    class SilverState : State
    {
        // Silver State意味着没有利息得
        public SilverState(State state):this(state.Balance,state.Account)
        {

        }
        public SilverState(double balance,Account account)
        {
            this.Balance = balance;
            this.Account = account;
            Interest = 0.00;
            LowerLimit = 0.00;
            UpperLimit = 1000.00;
        }

        public override void Deposit(double amount)  //存钱
        {
            this.Balance += amount;
            StateChangeCheck();
        }

        public override void PayInterest() //获取利息
        {
            this.Balance += Interest * Balance;  // 余额=余额+余额*利率
            StateChangeCheck();
        }

        public override void Withdraw(double amount)  //支取
        {
            this.Balance -= amount;
            StateChangeCheck();
        }

        private void StateChangeCheck()
        {
            if (this.Balance < LowerLimit) ///余额小于下限
            {
                Account.State = new RedState(this);
            }else if (this.Balance > LowerLimit)
            {
                Account.State = new GoldState(this);
            }
        }
    }
}
